package testCasalib 
{
    import flash.events.KeyboardEvent;
    import org.casalib.display.CasaMovieClip;
    import org.casalib.events.KeyComboEvent;
    import org.casalib.ui.Key;
    import org.casalib.ui.KeyCombo;
    import org.casalib.util.StageReference;

	
	/**
	 * ...
	 * @author ...
	 */
	public class key extends CasaMovieClip 
	{
		protected var _asdfCombo:KeyCombo;
        protected var _casaCombo:KeyCombo;
        protected var _key:Key;

		public function key() 
		{
			super();

            StageReference.setStage(this.stage);

            this._key = Key.getInstance();

            this._asdfCombo = new KeyCombo(new Array(65, 83, 68, 70));
            this._key.addKeyCombo(this._asdfCombo);

            this._casaCombo = new KeyCombo(new Array(67, 65, 83, 65));
            this._key.addKeyCombo(this._casaCombo);

            this._key.addEventListener(KeyComboEvent.DOWN, this._onComboDown);
            this._key.addEventListener(KeyComboEvent.RELEASE, this._onComboRelease);
            this._key.addEventListener(KeyComboEvent.SEQUENCE, this._onComboTyped);
            this._key.addEventListener(KeyboardEvent.KEY_DOWN, this._onKeyPressed);
            this._key.addEventListener(KeyboardEvent.KEY_UP, this._onKeyReleased);
        }

        protected function _onComboDown(e:KeyComboEvent):void {
            if (this._asdfCombo.equals(e.keyCombo)) {
                trace("User is holding down keys a-s-d-f.");
            }
        }

        protected function _onComboRelease(e:KeyComboEvent):void {
            if (this._asdfCombo.equals(e.keyCombo)) {
                trace("User no longer holding down keys a-s-d-f.");
            }
        }

        protected function _onComboTyped(e:KeyComboEvent):void {
            if (this._casaCombo.equals(e.keyCombo)) {
                trace("User typed casa.");
            }
        }

        protected function _onKeyPressed(e:KeyboardEvent):void {
            //trace("User pressed key with code: " + e.keyCode + ".");
        }

        protected function _onKeyReleased(e:KeyboardEvent):void {
            //trace("User released key with code: " + e.keyCode + ".");
        }

		
	}

}